using Cfg.Attributes;
using Cfg.ConfigValues;
using NUnit.Framework;

namespace Cfg.Test
{
    [TestFixture]
    public class EnumTest
    {
        public enum TestEnum
        {
            Foo,
            Bar,
            FooBar
        }

        [Test]
        public void GetEnumFirstValue()
        {
            var cv = new ValueBuilder(typeof(TestEnum), "Foo");
            var value = cv.GetValue();

            Assert.AreEqual(TestEnum.Foo, value);
        }

        [Test]
        public void GetEnumDefaultValueWhenDefaultNotDefined()
        {
            var cv = new ValueBuilder(typeof(TestEnum), "");
            var value = cv.GetValue();

            Assert.AreEqual(TestEnum.Foo, value);
        }


        [Test]
        public void GetEnumDefaultValueWhenDefaultDefined()
        {
            var attr = new object[] {new DefaultAttribute(TestEnum.Bar)};

            var cv = new ValueBuilder(typeof(TestEnum), attr, "", "", "");
            var value = cv.GetValue();

            Assert.AreEqual(TestEnum.Bar, value);
        }

        [Test]
        public void GetEnumSecondValue()
        {
            var cv = new ValueBuilder(typeof(TestEnum), "Bar");
            var value = cv.GetValue();

            Assert.AreEqual(TestEnum.Bar, value);
        }

        [Test]
        [ExpectedException(typeof(System.ArgumentException), ExpectedMessage = "Requested value 'Bars' was not found.")]
        public void TryGetEnumThatHasInvalidValue()
        {
            var cv = new ValueBuilder(typeof(TestEnum), "Bars");
            cv.GetValue();
        }
    }
}